# -*- coding: utf-8 -*-
"""
@Time : 2024/5/4 3:11 PM
@Author: imamhusan
@Des: 订单模型
"""
from tortoise import Model, fields


class Order(Model):
    name = fields.CharField(max_length=255, description='收货人')
    phone = fields.CharField(max_length=11, description='联系人')
    address = fields.CharField(max_length=512, description='收货地址')
    order_no = fields.CharField(max_length=64, description='订单号')
    total_count = fields.IntField(description='总数量')
    total_price = fields.IntField(description='总价格')
    state = fields.IntField(default=0, description='订单状态（0-未付款/1-已发送/2-已完成/3-已取消）')
    user = fields.ForeignKeyField('base.WxUser', related_name='orders', on_delete=fields.SET_NULL, null=True,
                                  description='下单用户')
    create_time = fields.DatetimeField(auto_now_add=True, description='创建时间')
    update_time = fields.DatetimeField(auto_now=True, description='更新时间')

    class Meta:
        table = 'oz_order'
        table_description = '订单表'


class OrderDetail(Model):
    pro_count = fields.IntField(description='商品数量')
    price = fields.IntField(description='商品价格')
    goods = fields.ForeignKeyField('base.Goods', related_name='goods_order_details')
    order = fields.ForeignKeyField('base.Order', related_name='order_details')
    create_time = fields.DatetimeField(auto_now_add=True, description='创建时间')
    update_time = fields.DatetimeField(auto_now=True, description='更新时间')

    class Meta:
        table = 'oz_order_detail'
        table_description = '订单详情表'

